angular.module('${menuCode}')
.filter('to_trusted', ['$sce', function ($sce) {
	return function (text) {
	    return $sce.trustAsHtml(text);
	};
}])
.controller("${widgetCode}Ctrl",function($scope,AppKit,$stateParams,$ionicBackdrop,$state){
	$scope.piName=$stateParams.piName;
	$scope.loadEliminatRate =function (){
		var url = '/aeaipm/services/ProjDefectStatistics/rest/findProjEliminatRateStatistics/'+$stateParams.piId+"/"+$stateParams.ptId;
		AppKit.getJsonApi(url).success(function(rspJson){
			$scope.eliminatRate = rspJson;
			if(rspJson.length == 0){
			  $scope.labelsEliminatRate = ['无记录'];
			  $scope.seriesEliminatRate = ['消缺率统计'];
			  $scope.coloursEliminatRate = ['#17C729'];
			  $scope.dataEliminatRate = [
			    [0]
			  ];
			}else{
				$scope.labelsEliminatRate = [];
				for( var i = 0 ; i < rspJson.length ; i++){
					$scope.labelsEliminatRate[i] = rspJson[i].testSchemeName;
				}
				
				$scope.seriesEliminatRate = ['消缺率统计'];
				$scope.coloursEliminatRate = ['#17C729'];
				$scope.dataEliminatRate = [[]];
				for(var i = 0 ; i < rspJson.length; i++){
					$scope.dataEliminatRate[0][i]= rspJson[i].testSchemeProblem;
				}
				
				 $scope.eliminatRateClick = function () {
					 $state.go("tab.eliminatrate-form",{"piId": $stateParams.piId,"ptId":$scope.ptId,"piName":$scope.piName});
				  };
			}
			
		})
	}	
	$scope.loadEliminatRate();
	
	$scope.loadProblemNum =function (){
		var url = '/aeaipm/services/ProjDefectStatistics/rest/findProjProblemStatistics/'+$stateParams.piId+"/"+$stateParams.ptId;
		AppKit.getJsonApi(url).success(function(rspJson){
			$scope.problemNum = rspJson;
			if(rspJson.length == 0){
			  $scope.labelsProblemNum = ['无记录'];
			  $scope.seriesProblemNum = ['问题数最多的功能统计'];
			  $scope.coloursProblemNum = ['#FB4443'];
			  $scope.dataProblemNum = [
			    [0]
			  ];
			}else{
				$scope.labelsProblemNum = [];
				for( var i = 0 ; i < rspJson.length ; i++){
					$scope.labelsProblemNum[i] = rspJson[i].testSchemeName;
				}
				
				$scope.seriesProblemNum = ['问题数最多的功能统计'];
				$scope.coloursProblemNum = ['#FB4443'];
				$scope.dataProblemNum = [[]];
				for(var i = 0 ; i < rspJson.length; i++){
					$scope.dataProblemNum[0][i]= rspJson[i].testSchemeProblem;
				}
				
				$scope.problemNumClick = function () {
					 $state.go("tab.problemnum-form",{"piId": $stateParams.piId,"ptId":$scope.ptId,"piName":$scope.piName});
				  };
			}
			
		})
	}
	$scope.loadProblemNum();
	
	$scope.loadFormDataStatistics =function (){
		var url = '/aeaipm/services/ProjDefectStatistics/rest/findProjFormDataStatistics/'+$stateParams.piId+"/"+$stateParams.ptId;
		AppKit.getJsonApi(url).success(function(rspJson){
			$scope.averageEliminatRate = rspJson.averageEliminatRate;
			$scope.sumTotalQuantity = rspJson.sumTotalQuantity;
			$scope.sumCompleteNum = rspJson.sumCompleteNum;
			$scope.sumNoCompleteNum = rspJson.sumNoCompleteNum;
			$scope.sumModifyNum = rspJson.sumModifyNum;
		})
	}
	$scope.loadFormDataStatistics();
	
	$scope.loadTestScheme =function (){
		var url = '/aeaipm/services/ProjDefectStatistics/rest/findProjTestScheme/'+$stateParams.piId;
		AppKit.getJsonApi(url).success(function(rspJson){
			$scope.testScheme = rspJson;
			$scope.items = $scope.testScheme;
			$scope.ret = {choice:$scope.items[0]}; 
			$scope.ptName=$scope.items[0].testSchemeName;
			$scope.ptId=$scope.items[0].testSchemeId;
		})
	}
	$scope.loadTestScheme();
	
	$scope.isShow=false;
	$scope.toggleOption=function(){
		if($scope.isShow==true){
			$scope.isShow=false;
		}else{
			$scope.isShow=true;
		}
	}
	
	$scope.changeItem=function(){
		  $scope.ptName=$scope.ret.choice.testSchemeName;
		  $scope.ptId=$scope.ret.choice.testSchemeId;
		  $stateParams.ptId=$scope.ptId;
		  $scope.loadProblemNum();
		  $scope.loadEliminatRate();
		  $scope.loadFormDataStatistics();
		}
	
});